import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Welcome from '../components/Welcome.vue'
import Users from '../components/user/Users.vue'
import Rights from '../components/power/Rights.vue'
import Roles from '../components/power/Roles.vue'
import Cate from '../components/goods/Cate.vue'
import Params from '../components/goods/Params.vue'
import List from '../components/goods/List.vue'
import Add from '../components/goods/Add.vue'
import Order from '../components/order/Order.vue'
import Report from '../components/report/Report.vue'
import Modula from '../components/Modular/Index.vue'
import Roleses from '../components/Role/Roleses.vue'
import Role from '../components/Role/Role.vue'
import Check from '../components/Role/Checks/check.vue'
import setWeight from '../components/Role/Checks/setWeight.vue'
import Students from '/src/components/Role/MyStu/Students.vue'
import NetStudent from '../components/Role/MyStu/NetStudent.vue'
import Netfloweer from '../components/Role/MyStu/Netfloweer.vue'
import yStudent from '../components/Role/MyStu/yStudent.vue'
Vue.use(VueRouter)

const routes = [
]

const router = new VueRouter({
  routes:[
	  {path:'/',redirect:'/login'},
	  {path:'/Login',component:Login},
	  {path:'/Home',component:Home,redirect:'/Welcome',
	  children:[
		{path:'/Welcome',component:Welcome},
		{path:'/users',component:Users},
		{path:'/rights',component:Rights},
		{path:'/roles',component:Roles},
		{path:'/categories',component:Cate},
		{path:'/params',component:Params},
		{path:'/goods',component:List},
		{path:'/goods/add',component:Add},
		{path:'/orders',component:Order},
		{path:'/reports',component:Report},
		{path:'/Modula',component:Modula},
		{path:'/Roleses',component:Roleses},
		{path:'/Role',component:Role},
		{path:'/Check',component:Check},
		{path:'/setWeight',component:setWeight},
		{path:'/Students',component:Students},
		{path:'/NetStudent',component:NetStudent},
		{path:'/Netfloweer',component:Netfloweer},
		{path:'/yStudent',component:yStudent}
	  ]},	  
  ]
})
//挂载路由导航守卫
router.beforeEach((to,from,next)=>{
	//to将要访问的路径 from从那个路径跳转而来  next 是一个函数，表示放行
	//next() 放行  next('/login')强制跳转
	if(to.path==='/login') return next();
	//获取token
	const tokenStr=window.sessionStorage.getItem('token')
	if(!tokenStr) return next('/login')
	next()
})
export default router
